package healththink

class Attribute{
    String name
    String description
    User user
    UserType userType
    Boolean isPublicType = false

    static hasMany = [facilities: FacilityAttributeLink]

    static constraints = {
        name(size:1..64, blank: false, unique:true)
        description(nullable:true)
        userType(nullable: true)
        user(nullable: true)
        isPublicType(nullable: true)
    }

    static mapping = {
        user lazy: false
    }
    
    String toString(){
        name
    }

    List Facilities()
    {
        return facilities.collect{it.facility}
    }
    
    List addToFacilities(Facility facility)
    {
        FacilityAttributeLink.link(this, facility)
        return facilities()
    }
    
    List removeFromFacilities(Facility facility)
    {
        FacilityAttributeLink.unlink(this, facilities)
        return facilities()
    }
    
}